package com.sit.estatemanagementserver.controller;

import com.sit.estatemanagementserver.enity.Response;
import com.sit.estatemanagementserver.enity.Room;
import com.sit.estatemanagementserver.service.FeeQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/fees") // 重构: 路径名统一风格
public class FeeQueryController {
    @Autowired
    private FeeQueryService feeQueryService;

    //按房间号查询缴费
    @GetMapping("/room/{roomNumber}")
    // 重构: 直接返回Room对象，让前端自行解析所需字段，更灵活
    public Response<Room> getRoomBalances(@PathVariable String roomNumber) {
        Room room = feeQueryService.getBalanceByRoomNumber(roomNumber);
        if (room != null) {
            return Response.success(room);
        } else {
            return Response.error("房间不存在，查询失败！");
        }
    }
}